#include <stdio.h>
int main(){
	int i,n,t;
	int m = 0; 
	scanf("%d",&n);
	int a[n];
	for(i = 0;i<n;i++){
		scanf("%d",&a[i]);
	}for(i = 1;i<n;i++){
		if(a[i]<a[m]){
			m = i;
		}
	}t = a[0];a[0] = a[m];a[m] = t;
	for(i = 1;i<n;i++){
		if(a[i]>a[m]){
			m  = i;
		}
	}t = a[n-1];a[n-1] = a[m];a[m] = t;
	for(i = 0;i<n;i++){
		printf("%d",a[i]);printf(" ");
	}return 0;
}
